import react, { useState, useEffect } from "react";

function useCommonSelectOptions({ func, params = {}, immediate = true }) {
  const [list, setList] = useState([]);

  const getAll = async (innerParmas = {}) => {
    const res = await func({
      status: 1,
      ...params,
      ...innerParmas,
    });

    if (res.data) {
      setList(res.data);
    }
  };

  useEffect(() => {
    if (immediate) {
      getAll();
    }
  }, [func]);
  return { list, refresh: getAll };
}

export default useCommonSelectOptions;
